package com.ctl.juc;

import java.util.List;
import java.util.concurrent.CountDownLatch;

public class VolatileTest {
    private static volatile int i;
    static CountDownLatch countDownLatch = new CountDownLatch(3);

    public Long say(String name, int age) {
        return Long.valueOf(name.hashCode()+age);
    }
    public Long say(List<String> name, List<Integer> age) {
        return Long.valueOf(name.hashCode()+age.size());
    }

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            for (int k = 0; k < 10000; k++) {
                i++;
            }
            countDownLatch.countDown();
        }).start();
        new Thread(() -> {
            for (int k = 0; k < 10000; k++) {
                i++;
            }
            countDownLatch.countDown();
        }).start();
        new Thread(() -> {
            for (int k = 0; k < 10000; k++) {
                i++;
            }
            countDownLatch.countDown();
        }).start();
        countDownLatch.await();
        Thread.sleep(1000000000);
        System.out.println(i);//运行多次不一定等于30000
    }
}
